
<?php
use \Hyang\Db;
use \Hyang\Model;
class testController extends \Hyang\Controller
{
    public function indexAction()
    {
        $data = get_defined_constants(true);
        debug($this,true);
    }
    public function headAction()
    {
        $url = isset($_GET['url'])? $_GET['url']:'http://www.gzjyfw.gov.cn/';
        $arr = get_headers($url);
        debug($arr,true);
        echo '<br>get_current_user: '.get_current_user();
        echo '<br>getcwd: '.getcwd();
        echo '<br>gethostname: '.gethostname();
        echo '<br>getmygid: '.getmygid();
        echo '<br>getmyinode: '.getmyinode();
        echo '<br>getmypid: '.getmypid();
        echo '<br>getmyuid: '.getmyuid();
        echo '<br>getrandmax: '.getrandmax();
        //echo '<br>gethostbyaddr:'.gethostbyaddr('14.215.177.37');
        echo '<br>获取当前请求的所有请求头信息:';
        debug(getallheaders(),true);
        /*
        // 邮件发送
        $hd = 'From: webmaster@example.com' . "\r\n" .
              'Reply-To: webmaster@example.com' . "\r\n" .
              'X-Mailer: PHP/' . phpversion();
        mail('brximl@163.com', 'My Subject', '邮件发送测试',$hd);
        */
    }
    public function dbAction()
    {
        $db = new Db();
        debug($db,true);
        $data = $db->query('select * from "sys_user"',true);
        debug($data,true);
    }
    // mysql 数据库连测试-db
    public function mysqlAction()
    {
        $opt = [
            'type'=>'mysql',
            'dbname'=>'cro',
            'user' => 'root',
            'password' => '151001',
        ];
        $db = new Db($opt);
        debug($db->query('select * from net_user')
            ,true);
        debug([
            '数据绑定测试',
            $db->query('select * from net_user where user_code=?',['1490015909']),
            $db->fetchRow('select * from net_user where user_code=:user_code',['user_code'=>'1490015909'])
            ,$db->select('sys_visitor')
            ]
            ,true);
            
    }
    // oracle 数据库连测试-db
    public function oracleAction()
    {
        $db = new Db();
        debug($db,true);
        $data = $db->fetchRow('select * from "ird1000c"');
        debug(['普通查询',$data],true);
        // 数据绑定
        $data = $db->query('select * from "ird1000c" where "organ_id"=:organ_id',['organ_id'=>'S00801']);
        debug(['数据绑定测试',$data],true);
        // 数据查询测试
        debug(['数据自定义查询'
            //,$db->select('ird1000c')
        ],true);
    }
    public function modelAction()
    {
        $m = new Model();
        $u = new User();
        // oracle
        debug([
            '数据模式测试工具-ORacle'
            ,$m
            //,$u->get('S00965')
            //,$u->where('"administv_no"=\'500100\'')->count()
            ,$u->where(['administv_name'=>'重庆市'])->page(1,3)->pageBar()->select()
            //,$u->build()->data(['administv_name'=>'重庆市','organ_id'=>'S5841'])->add()
            //,$u->table('sys_user')->where()->count()
            ,$u->table('sys_user')->build()->data(['administv_name'=>'重庆市','organ_id'=>'S5841'])->add()
            //,$u->table('sys_user')->data(['administv_name'=>'重庆市','organ_id'=>'S5841'])->add()
            ,$u->where(['TABLE_NAME'=>'bak1001c'])->table('USER_TABLES')->count()
            //,$u->db->_error()
        ],true);
        /*
        $u->havingTb(null,function($ret,$obj){
            echo '<br>回调函数-----><br>';
            echo '<br>having';
            if($ret) echo '<br>数据表存在';
            else echo '<br>none';
            echo '<br><-----<br>';
        });
        */
        // mysql
        $u1 = new MyUser();
        debug([
            '数据模式测试工具-MySQL'
            ,$u1
            ,$u1->get('17185958')
            ,$u1->db->fetchOne('show tables like "finc_set"')
            //,$u1->count()
            ,$u1->build()->data(['administv_name'=>'重庆市','organ_id'=>'S5841'])->add()
        ],true); 
    }
}
           
                